<f:subview xmlns:f="http://java.sun.com/jsf/core"
  xmlns="http://www.w3.org/1999/xhtml"
  xmlns:c="http://java.sun.com/jstl/core"
  xmlns:h="http://java.sun.com/jsf/html"
  xmlns:a4j="http://richfaces.org/a4j"
  xmlns:nxu="http://nuxeo.org/nxweb/util"
  xmlns:nxl="http://nuxeo.org/nxforms/layout"
  xmlns:ui="http://java.sun.com/jsf/facelets"
  id="#{widget.id}">

  <c:if test="#{widget.mode != 'edit'}">

    <h:outputText value="#{messages['label.files.noAttachedFiles']}"
      rendered="#{empty field}" />

    <table>
      <tbody>
        <nxu:inputList value="#{field}" id="#{widget.id}_table" model="model"
          rendered="#{not empty field}">
          <nxl:subWidget>
            <tr>
              <td class="fieldColumn">
                <nxl:widget widget="#{widget}"
                  value="#{model.rowData}" />
              </td>
            </tr>
          </nxl:subWidget>
        </nxu:inputList>
      </tbody>
    </table>

  </c:if>

  <c:if test="#{widget.mode == 'edit'}">

    <c:set var="showActions"
      value="#{isEditMode and (not widgetProperty_hideDeleteButton or widgetProperty_orderable)}" />
    <nxu:set var="listClientId" value="#{nxu:componentAbsoluteId(component, widget.id).substring(1)}">

    <div id="#{listClientId}_panel" class="widgetPanel listWidgetPanel #{widgetProperty_styleClass}">

      <nxu:jsInputList value="#{field}" id="#{widget.id}" model="model"
        removeEmpty="#{widgetProperty_removeEmpty}"
        number="#{widgetProperty_number}"
        template="#{nxd:propertyDefaultValue(widget.fieldDefinitions[0].propertyName)}"
        required="#{widgetProperty_required}" diff="#{widgetProperty_diff}">

        <h:panelGrid columns="#{isEditMode and showActions?2:1}" styleClass="listItem">
          <c:if test="#{showActions}">
            <h:panelGroup styleClass="listWidgetActionsTable" id="#{widget.id}_actions">
              <ui:include src="/widgets/js_list_widget_template_actions.xhtml" />
            </h:panelGroup>
          </c:if>
          <h:panelGroup>
            <h:inputHidden>
              <f:passThroughAttribute name="name" value="#{listClientId}:#{isListTemplate ? 'TEMPLATE_INDEX_MARKER:': ''}rowIndex[]" />
              <f:attribute name="value" value="#{isListTemplate ? 'TEMPLATE_INDEX_MARKER' : model.rowIndex}"/>
            </h:inputHidden>
            <table>
              <tbody>
                <nxl:subWidget>
                  <tr>
                    <td class="fieldColumn">
                      <nxl:widget widget="#{widget}" value="#{model.rowData}"
                        onclick="#{widgetProperty_onclick}" onchange="#{widgetProperty_onchange}" />
                    </td>
                  </tr>
                </nxl:subWidget>
              </tbody>
            </table>
          </h:panelGroup>
        </h:panelGrid>

      </nxu:jsInputList>

      <ui:fragment rendered="#{isEditMode and not widgetProperty_hideAddButton}">
        <a id="#{listClientId}_add" class="button smallButton listWidgetActionAdd" href="#nogo"
           onclick="return nuxeo.utils.addFromListTemplate('#{listClientId}', jQuery(this).prev());">
          <h:outputText value="#{nxu:test(empty widgetProperty_addLabel, messages['command.addNewAttachedFile'], nxu:test(widget.translated, messages[widgetProperty_addLabel], widgetProperty_addLabel))}" />
        </a>
      </ui:fragment>

      <h:message styleClass="errorMessage" for="#{widget.id}"
        id="#{widget.id}_message" />

    </div>
    </nxu:set>

  </c:if>

</f:subview>